﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using System.Xml;

namespace Winwise.SPWebConfig.Core
{
    [System.Runtime.InteropServices.GuidAttribute("A0B869FF-7C8D-4FB8-BDF2-07139F1542E1")]
    public abstract class WebConfigModification : SPAutoSerializingObject
    {
        [Persisted]
        private List<SPUrlZone> m_Zones;

        [Persisted]
        private string m_DisplayName;

        [Persisted]
        private Guid m_ID;

        public Guid ID
        {
            get
            {
                return m_ID;
            }
            set
            {
                m_ID = value;
            }
        }

        public WebConfigModification()
        {
            if (m_ID == Guid.Empty)
            {
                m_ID = Guid.NewGuid();
            }
        }

        public string DisplayName
        {
            get
            {
                return m_DisplayName;
            }
            set
            {
                m_DisplayName = value;
            }
        }

        public List<SPUrlZone> Zones
        {
            get
            {
                if (m_Zones == null)
                {
                    m_Zones = new List<SPUrlZone>()
                    {
                        SPUrlZone.Default,  SPUrlZone.Intranet, SPUrlZone.Internet, SPUrlZone.Custom,SPUrlZone.Extranet
                    };
                }
                return m_Zones;
            }
            set
            {
                m_Zones = value;
            }
        }

        internal string LastOperationMessage { get; set; }


        public abstract void ApplyModification(XmlDocument doc, SPUrlZone zone, SPWebApplication webapp);
        public abstract void RemoveModification(XmlDocument doc, SPUrlZone zone, SPWebApplication webapp);

        public abstract string FriendlyTypeName { get; }
        public abstract bool SupportEditing { get; }
        public virtual string AdminPage { get { return ""; } }
        public virtual void Validate()
        {
            if (string.IsNullOrEmpty(this.DisplayName))
            {
                throw new Exception("DisplayName property should not be null or empty");
            }
        }
         
    }
}
